layui.use(['table', 'admin', 'ax','laydate'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var laydate = layui.laydate;
    
    laydate.render({
      elem: '#startTime'
        	,value:new Date()
    });

    laydate.render({
      elem: '#endTime'
        	,value:new Date()
    });

    var ToolExpress = {
        tableId: "toolExpressTable"
    };

    /**
     * 初始化表格的列
     */
    ToolExpress.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键'},
            {field: 'v1', sort: true, title: '出库单号'},
            {field: 'v3', sort: true, title: '快递公司'},
            {field: 'orderNumber', sort: true, title: '快递单号'},
            {field: 'goodsNumber', sort: true, title: '商品组合', totalRowText: '合计：'},
            {field: 'num', sort: true, title: '组合数量'},
            {field: 'v2', sort: true, title: '重量', totalRow: true},
        ]];
    };

    /**
     * 点击查询按钮
     */
    ToolExpress.search = function () {
        var queryData = {};
        queryData['v4'] = $("#v4").val();
        queryData['v1'] = $("#v1").val();
        queryData['v3'] = $("#v3").val();
        queryData['condition'] = $("#condition").val();
        queryData['goodsNumber'] = $("#goodsNumber").val();
        queryData['num'] = $("#num").val();
        queryData['startTime'] = $("#startTime").val();
        queryData['endTime'] = $("#endTime").val();
        table.reload(ToolExpress.tableId, {
            where: queryData, page: {curr: 1},
             done:function () {
            }
        });
    };

    /**
     * 导出excel按钮
     */
    ToolExpress.exportExcel = function () {
        var checkRows = table.checkStatus(ToolExpress.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
        	console.log()
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + ToolExpress.tableId,
        url: Feng.ctxPath + '/toolExpress/findlist',
        page: true,
        limit: 5000,
        height: "full-60",
        totalRow: true,
        toolbar: '#toolbarfrom',
		limits:[5000,20000,60000,100000,150000],
        cellMinWidth: 100,
        cols: ToolExpress.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        ToolExpress.search();
    });

    // 导出excel
    $('#btnExp').click(function () {
        ToolExpress.exportExcel();
    });
});
